# -*- coding: utf-8 -*-

# File Name： get_external_truck_number_result
# Description :
# Author : lirui
# create_date： 2022/6/10
# Change Activity:
import json
import pprint
import time

import requests

# ip = '127.0.0.1'
from ml.cv.misc.img_io import write_img
from ml.cv.util.img_util import ImageTransform

ip = '10.123.31.152'


def main():
    for i in range(100):
        time.sleep(2)
        res_lst = json.loads(requests.post(url=rf'http://{ip}:8080/car_num/get_plate_num_recognize_result').text)
        for res in res_lst:
            pprint.pprint(res)
            img_name = res['image_name']
            data = {'image_name': img_name}
            data = json.dumps(data)
            res = requests.post(url=rf'http://{ip}:8080/car_num/get_image', data={'data': data})
            res = json.loads(str(res.text))
            img_base = res['img_base64']
            img = ImageTransform.base64_to_img(img_base)
            write_img(img, img_name)


if __name__ == '__main__':
    main()
